package com.fps.web.dao.impl;
import org.springframework.stereotype.Repository;
import com.fpswork.core.exception.exception.BusinessException;
import com.fpswork.core.model.PageEntity;
import com.fpswork.datamodel.basedao.BaseDao;
import com.fpswork.util.BeanUtils;
import com.fpswork.util.StringUtil;
import com.fps.web.dao.BaseattachDao;
import com.fps.web.model.Baseattach;
@Repository 
public class BaseattachDaoImpl extends BaseDao implements BaseattachDao{
    
	public PageEntity queryBaseattachList(PageEntity pageEntity)  throws BusinessException{
		String sql="select * from baseattach";
		pageEntity.setSql(sql);
		return  this.queryForPageEntity(pageEntity);
	}
	public Baseattach queryBaseattachByID(String id)  throws BusinessException{
		return  this.get(Baseattach.class, id);
	}
	public Baseattach addBaseattach(Baseattach baseattach)  throws BusinessException{
		//校验是否为空
		if(baseattach==null){
			throw new BusinessException("传入数据为空！");
		}
		if(StringUtil.isEmpty(baseattach.getId())){
			this.save(baseattach);
		}else{
			throw new BusinessException("已存在数据！");
		}
		return baseattach;
	}
	public Baseattach updateBaseattach(Baseattach baseattach)  throws BusinessException{
		Baseattach baseattach1= this.get(Baseattach.class, baseattach.getId());
		if(baseattach1==null||StringUtil.isEmpty(baseattach1.getId())){
	 		throw new BusinessException("没有找到数据！");
		}else{
			BeanUtils.copyProperties(baseattach1, baseattach);
			this.update(baseattach1);
		}
		return baseattach1;
	}
	public Boolean deleteBaseattach(Baseattach baseattach)  throws BusinessException{
		this.delete(this.get(Baseattach.class, baseattach.getId()));
		
		return true;
	}
}
